﻿@model MsForgeReboot.Web.Models.UrlPointeViewModel

<script type="text/javascript">    
    $(document).ready(function() {

        $("#@Model.Title").change(function() {

            var str = $("#@Model.Title").val().toLowerCase();

            var from = "čćšãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;";
            var to   = "ccsaaaaaeeeeeiiiiooooouuuunc------";

            str = str.replace("đ", "dj");

            for (var i = 0, l = from.length; i < l; i++) {
                str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
            }

            str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
                .replace(/\s+/g, '-') // collapse whitespace and replace by -
                .replace(/-+/g, '-'); // collapse dashes

            $("#@Model.UrlPointer").val(str);
            $("#@Model.SpanId").text(str);

        });
    });
</script>